package com.venutech.gongan.api;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.service.ISysUserService;
import com.venutech.gongan.entity.TbOpWork;
import com.venutech.gongan.service.ITbOpWorkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 运维Controller
 * 
 * @author linxb
 * @date 2023-09-19
 */
@Api(value = "运维报表管理", tags = "运维报表管理")
@RestController
@RequestMapping("/gongan/tbOpWork")
public class TbOpWorkController extends BaseController
{

    @Autowired
    private ITbOpWorkService tbOpWorkService;
    @Autowired
    private ISysUserService sysUserService;


    /**
     * 查询运维列表
     */
    @ApiOperation("查询运维报表")
    @GetMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbOpWork tbOpWork)
    {
        startPage();
        List<TbOpWork> list = tbOpWorkService.selectTbOpWorkList(tbOpWork);
        return getDataTable(list);
    }

    /**
     * 导出运维列表
     */
    @ApiOperation("导出运维报表")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export()
    {
        TbOpWork tbOpWork=new TbOpWork();
        List<TbOpWork> list = tbOpWorkService.selectTbOpWorkList(tbOpWork);
        ExcelUtil<TbOpWork> util = new ExcelUtil<TbOpWork>(TbOpWork.class);
        return util.exportExcel(list, "运维数据", "运维数据");
    }



    /**
     * 新增保存运维
     */
//    @ApiOperation("新增保存运维")
//    @PostMapping("/addTbOpWork")
//    @ResponseBody
//    public AjaxResult addSave(@RequestBody TbOpWork tbOpWork)
//    {
//        LoginUser loginUser = SecurityUtils.getLoginUser();
//        tbOpWork.setRepairMan(loginUser.getUserId().toString());
//        SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        Date date = new Date(System.currentTimeMillis());
//        System.out.println(formatter.format(date));
//        tbOpWork.setRepairTime(date);
//        tbOpWork.setFaultTime(date);
//        return toAjax(tbOpWorkService.insertTbOpWork(tbOpWork));
//    }


    /**
     * 修改保存运维
     */
//    @ApiOperation("修改保存运维")
//    @PostMapping("/editTbOpWork")
//    @ResponseBody
//    public AjaxResult editSave(@RequestBody TbOpWork tbOpWork)
//    {
//        LoginUser loginUser = SecurityUtils.getLoginUser();
//        TbOpWork opWork=new TbOpWork();
//        BeanUtils.copyProperties(tbOpWork,opWork);
//        opWork.setRepairMan(loginUser.getUserId().toString());
//        List<TbOpWork> opWorkList=tbOpWorkService.selectTbOpWorkList(opWork);
////        tbOpWork.setRepairMan(loginUser.getUserId().toString());
////        List<TbOpWork> opWorkList=tbOpWorkService.selectTbOpWorkList(tbOpWork);
//        SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        Date date = new Date(System.currentTimeMillis());
//        if(opWorkList.size()>0){
//            tbOpWork.setRepairTime(date);
//            tbOpWork.setFaultTime(date);
//            return toAjax(tbOpWorkService.updateTbOpWork(tbOpWork));
//        }else{
////            if(opWorkList.get(0).getRepairStatus().equals(tbOpWork.getRepairStatus()) || "初始工单状态".equals(tbOpWork.getRepairStatus())){//
////                tbOpWork.setRepairMan(loginUser.getUserId().toString());
////                tbOpWork.setRepairTime(date);
////                tbOpWork.setFaultTime(date);
////                return toAjax(tbOpWorkService.updateTbOpWork(tbOpWork));
////            }else{
////                tbOpWork.setResponseMan(loginUser.getUserId().toString());
////                tbOpWork.setResponseTime(date);
////                return toAjax(tbOpWorkService.updateTbOpWork(tbOpWork));
////            }
//
//
//            tbOpWork.setResponseMan(loginUser.getUserId().toString());
//            tbOpWork.setResponseTime(date);
//            return toAjax(tbOpWorkService.updateTbOpWork(tbOpWork));
//        }
//
//
//    }
//
//    /**
//     * 删除运维
//     */
////    @ApiOperation("删除运维")
//    @PostMapping( "/removeTbOpWork")
//    @ResponseBody
//    public AjaxResult remove(@RequestBody String ids)
//    {
//        return toAjax(tbOpWorkService.deleteTbOpWorkByOpWorkIds(ids));
//    }
//
//    /**
//     * 删除运维
//     */
//    @ApiOperation("删除运维")
//    @GetMapping( "/deleteTbOpWorkByOpWorkId/{id}")
//    @ResponseBody
//    public AjaxResult deleteTbOpWorkByOpWorkId(@PathVariable Long id)
//    {
//        return toAjax(tbOpWorkService.deleteTbOpWorkByOpWorkId(id));
//    }
}
